package com.tsunami.auth.controller;

import com.tsunami.auth.service.auth.IClientsService;
import com.tsunami.authority.dto.auth.ClientsSaveDTO;
import com.tsunami.authority.dto.auth.ClientsUpdateDTO;
import com.tsunami.authority.entity.auth.Clients;
import com.tsunami.base.R;
import com.tsunami.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname ClientsController
 * @Description TODO
 * @Date 2021-11-30 17:05
 * @Created by lx
 */
@RestController
@RequestMapping("/clients")
@Api(value = "Clients", tags = "授权客户端管理")
public class ClientsController {

    @Autowired
    IClientsService clientsService;

    @GetMapping("page")
    @ApiOperation(notes = "授权客户端列表（分页）",value = "获取授权客户端列表")
    @SysLog("获取授权客户端列表")
    public R list(Integer pageNum,
                  Integer pageSize,
                  String orderByColumn,
                  String isAsc,
                  Clients data){
        return clientsService.selectPageList(data);
    }
    @PostMapping("save")
    @ApiOperation(notes = "添加客户端",value = "添加客户端")
    @SysLog("添加客户端")
    public R save(ClientsSaveDTO entity){
        clientsService.saveClients(entity);
        return R.ok();
    }

    @ApiOperation(value = "更新客户端", notes = "更新服务")
    @PostMapping("/update")
    @SysLog("更新服务")
    public R update(@Validated ClientsUpdateDTO data){
        clientsService.updateClient(data);
        return R.ok();
    }

    @ApiOperation(value = "生成客户端秘钥", notes = "生成客户端秘钥")
    @PostMapping("/secret")
    @SysLog("生成客户端秘钥")
    public R secret(String serverCode,String appId){
        String secret = clientsService.updateSecret(serverCode,appId);
        return R.ok().data("data",secret);
    }

    @ApiOperation(value = "更新授权跳转地址", notes = "更新授权跳转地址")
    @PostMapping("/updateRedirectUri")
    @SysLog("更新授权跳转地址")
    public R updateRedirectUri(String appId,String redirectUri){
        clientsService.updateRedirectUri(appId,redirectUri);
        return R.ok();
    }

}
